package battlenetwork;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.KeyListener;

import javax.swing.JFrame;

public class MainFrame extends JFrame{
	
	private KeyListener keyListener;
	
	public MainFrame(KeyListener keyListener){
		super();
		this.setSize(1600, 900);
		this.setVisible(true);
		this.keyListener = keyListener;
		addKeyListener(keyListener);
	}
	
	
	public void paint(Graphics g, Game game){
		super.paint(g);
		Graphics2D g2d = (Graphics2D)g;
		g2d.setBackground(Color.black);
		g2d.setColor(Color.black);
		drawGrid(g2d);
		drawPlayer(game.getPlayerPos(), g2d);
		drawEnemies(g2d, game);
	}
	
	public void drawGrid(Graphics2D g2d){
		g2d.setColor(Color.black);
		g2d.fillRect(0, 0, 1600, 900);
		g2d.setColor(Color.white);
		for(int i = 0; i < 6; i++){
			for(int j = 0; j < 3; j++){
				g2d.drawRect(200 + 200*i, 150 + 200*j, 200, 200);
			}
		}
		
		
	}
	
	public void drawPlayer(Point pos, Graphics2D g2d){
		g2d.setColor(Color.blue);
		g2d.fillOval(275+ pos.x*200, 225 + pos.y*200, 50, 50);
	}
	
	public void drawEnemies(Graphics2D g2d, Game game){
		g2d.setColor(Color.red);
		for(int i = 0; i < 6; i++){
			for(int j = 0; j < 3; j++){
				if(!game.getTiles()[i][j].isFriendly()){
					if(!game.getTiles()[i][j].isFree()){
						g2d.fillOval(275+ i*200, 225 + j*200, 50, 50);
					}
				}
			}
		}
	}
	
	public void redraw(Game game){
		this.paint(this.getGraphics(), game);
	}
	
	
	
	
}
